import request from "@/utils/request";

import type { ICategory, IAttrList, IAttr } from "./model"; // 数据的类型

enum API {
  CATEGORY1LIST = "/admin/product/getCategory1", // 一级分类的接口
  CATEGORY2LIST = "/admin/product/getCategory2/", // 二级分类的接口
  CATEGORY3LIST = "/admin/product/getCategory3/", // 三级分类的接口
  ATTRLIST = "/admin/product/attrInfoList/", // 平台属性数据的接口
  ADDORUPDATEATTR = "/admin/product/saveAttrInfo", // 添加或修改平台属性的接口
  DELETEATTR = "/admin/product/deleteAttr/", // 删除平台属性的接口
}

// 获取一级分类的数据
export const reqCategory1List = () =>
  request.get<any, ICategory>(API.CATEGORY1LIST);

// 获取二级分类的数据
export const reqCategory2List = (category1Id: number | string) =>
  request.get<any, ICategory>(API.CATEGORY2LIST + category1Id);

// 获取三级分类的数据
export const reqCategory3List = (category2Id: number | string) =>
  request.get<any, ICategory>(API.CATEGORY3LIST + category2Id);

// 获取平台属性数据
export const reqAttrList = (
  category1Id: string | number,
  category2Id: string | number,
  category3Id: string | number
) =>
  request.get<any, IAttrList>(
    API.ATTRLIST + `${category1Id}/${category2Id}/${category3Id}`
  );

// 添加或修改平台属性
export const reqAddOrUpdateAttr = (data: IAttr) =>
  request.post<any, any>(API.ADDORUPDATEATTR, data);

// 删除平台属性
export const reqDeleteAttr = (attrId: number | undefined) =>
  request.delete<any, any>(API.DELETEATTR + attrId);
